package com.dqy.twserver.server.handle.ehandle;

import com.dqy.twserver.server.dto.GameDto;
import com.dqy.twserver.server.support.SupportMap;
import com.dqy.twserver.server.support.data.PlayerInfo;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GameEventRegistHandle implements GameEventHandle{
    static Logger logger = LoggerFactory.getLogger(GameEventRegistHandle.class);
    @Override
    public void handle(GameDto req, NioSocketChannel channel) {
        logger.info("[GameEventRegistHandle] start");
        String playerName = req.getPlayerName();
        String playerPass = req.getPlayerPass();
        GameDto resp=new GameDto();
        if(SupportMap.playerDataMap.get(playerName)==null){
            PlayerInfo playerInfo=new PlayerInfo(playerName,playerPass);
            SupportMap.playerDataMap.put(playerName,playerInfo);
            resp.setSts(200);
            resp.setInfo("注册成功");
            logger.info("[GameEventRegistHandle] {}注册成功}",playerName);
        }else {
            resp.setInfo("用户已存在");
            resp.setSts(400);
            logger.info("[GameEventRegistHandle] {}用户已存在}",playerName);
        }
        channel.writeAndFlush(resp);
        logger.info("[GameEventRegistHandle] end");
    }
}
